package library.and.xps.com.step.view.activity;

import android.os.Build;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.view.WindowManager;
import android.widget.TextView;

import com.jude.utils.JUtils;
import com.squareup.okhttp.Request;

import library.and.xps.com.step.R;
import library.and.xps.com.step.URLConstants;
import library.and.xps.com.step.m.model.RequestParams;
import library.and.xps.com.step.m.netapi.OkHttpClientUtils;
import library.and.xps.com.step.net.ResponceWrapper;
import library.and.xps.com.step.util.RequestCallback;
import library.and.xps.com.step.view.base.BaseActivity;

public class FindBackPassActivity extends BaseActivity implements View.OnClickListener {
    EditText etPhoneNumber;
    EditText etnewPassword;
    EditText etVerifyNum;

    Button btLogin;
    TextView tvGetVerify;

    @Override
    protected int getLayout() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

        return R.layout.activity_findbackpass;
    }

    @Override
    protected void setData() {

    }

    @Override
    protected void init() {
        etPhoneNumber = r2v(R.id.et_phoneNumber);
        etnewPassword = r2v(R.id.et_newpassword);

        btLogin = r2v(R.id.bt_findback);
        btLogin.setOnClickListener(this);
        btLogin.setOnClickListener(this);
        etVerifyNum = r2v(R.id.et_verifyNum);
        tvGetVerify = r2v(R.id.tv_getVerify);
        tvGetVerify.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.tv_getVerify:
                OkHttpClientUtils.getDataAsync(this, URLConstants.USER.getVerifyCode + "/?phone=" + etPhoneNumber.getText().toString(), new RequestCallback() {
                    @Override
                    public void onFailure(Request request, Exception e) {
                        JUtils.Log("getDataAsync", "onfailure");
                        e.printStackTrace();
                    }

                    @Override
                    public void onResponse(ResponceWrapper response) {
                        JUtils.Log("getDataAsync", response.getBody());
                    }

                    @Override
                    public void onStart() {

                    }
                }, "");

                break;
            case R.id.bt_findback:
                findback();
                break;
            case R.id.tv_register:

                break;
            case R.id.tv_findpass:

                break;
            case R.id.iv_third_qq:

                break;
            case R.id.iv_third_weibo:

                break;
            case R.id.iv_third_weixin:

                break;
        }
    }


    void findback() {
        String jsonObject = RequestParams.getNewInstance()
                .setPhone(etPhoneNumber.getText().toString())
                .setPassword(etnewPassword.getText().toString())
                .setVerificationcode(etVerifyNum.getText().toString())
                .getJson().toString();

        OkHttpClientUtils.postJsonStringAsync(this, URLConstants.TEAM.PassFindback, jsonObject, new RequestCallback() {
            @Override
            public void onFailure(Request request, Exception e) {
                JUtils.Log("getDataAsync", "onFailure");
            }

            @Override
            public void onResponse(ResponceWrapper response) {
                    JUtils.Log("getDataAsync", response.getBody());
            }

            @Override
            public void onStart() {

            }

        }, "");
    }

}
